<extend name="Layout/ins_page" />
<block name="content">
{:W('PageHeader/simple',array('name'=>$siteName,'search'=>'N'))}
<div class="operate panel panel-default {$allowEdit ? '' : 'hidden'}" style="margin-bottom: 50px;">
    <div class="panel-body">
        <div class="pull-left">
            <button id="button-add-joker" type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target=".add-joker">新增</button>
            |
            <a onclick="del()"  class="btn btn-sm btn-danger">删除</a>
        </div>
        <div class="pull-right">
            <label style="margin-right: 1em;"><input id="need_leader_check" data-siteid="{$siteId}" name="need_leader_check" type="checkbox" {$siteInfo['need_leader_check'] ? 'checked' : ''}>需要领导审核</label>
            <label style="margin-right: 1em;"><input id="need_maintain_check" data-siteid="{$siteId}" name="need_maintain_check" type="checkbox" {$siteInfo['need_maintain_check'] ? 'checked' : ''}>需要维护审核</label>
            <button type="button" onclick="apply()" class="btn btn-sm btn-success">确定发起审核</button>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-sm-9">
        <form id="form-joker" action="#">
            <input type="hidden" name="site_id" value="{$siteId}">
            <volist name="majorList" id="major" key="key">
                <div class="operate panel panel-default">
                    <div class="panel-body">
                        <div class="pull-left">
                            <h4>{$major}</h4>
                        </div>
                        <div class="row">
                            <table data-major="{$major}" class="table table-bordered"></table>
                        </div>
                    </div>
                </div>
            </volist>
        </form>
        <style>
            .thumb {
                width: 100%;
            }

            img.remove-pic {
                <?= $allowEdit ? '' : 'display:none;' ?>
            }

            label.add-img[data-href=""] + img.remove-pic {
                display: none;
            }
        </style>
        <form id="form-pic" action="{:U('site/saveA')}" method="post">
            <input type="hidden" name="id" value="{$siteId}">
            <div class="operate panel panel-default">
                <div class="panel-body col-md-5">
                    <div>
                        <h4>整体照片</h4>
                    </div>
                    <div class="row">
                        <div class="col col-md-6">
                            <input type="hidden" name="pic_all_1" value="{$siteInfo['pic_all_1']}">
                            <label data-name="pic_all_1" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_all_1']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_all_1" src="{$siteInfo['pic_all_1_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-6">
                            <input type="hidden" name="pic_all_2" value="{$siteInfo['pic_all_2']}">
                            <label data-name="pic_all_2" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_all_2']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_all_2" src="{$siteInfo['pic_all_2_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                    </div>
                    <div>
                        <h4>其他照片</h4>
                    </div>
                    <div class="row">
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_other_1" value="{$siteInfo['pic_other_1']}">
                            <label data-name="pic_other_1" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_other_1']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_other_1" src="{$siteInfo['pic_other_1_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_other_2" value="{$siteInfo['pic_other_2']}">
                            <label data-name="pic_other_2" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_other_2']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_other_2" src="{$siteInfo['pic_other_2_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_other_3" value="{$siteInfo['pic_other_3']}">
                            <label data-name="pic_other_3" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_other_3']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_other_3" src="{$siteInfo['pic_other_3_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_other_4" value="{$siteInfo['pic_other_4']}">
                            <label data-name="pic_other_4" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_other_4']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_other_4" src="{$siteInfo['pic_other_4_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_other_5" value="{$siteInfo['pic_other_5']}">
                            <label data-name="pic_other_5" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_other_5']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_other_5" src="{$siteInfo['pic_other_5_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_other_6" value="{$siteInfo['pic_other_6']}">
                            <label data-name="pic_other_6" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_other_6']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_other_6" src="{$siteInfo['pic_other_6_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                    </div>
                </div>
                <div class="panel-body col-md-7">
                    <div>
                        <h4>场景照片</h4>
                    </div>
                    <div class="row">
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_1" value="{$siteInfo['pic_env_1']}">
                            <label data-name="pic_env_1" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_1']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_1" src="{$siteInfo['pic_env_1_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_2" value="{$siteInfo['pic_env_2']}">
                            <label data-name="pic_env_2" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_2']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_2" src="{$siteInfo['pic_env_2_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_3" value="{$siteInfo['pic_env_3']}">
                            <label data-name="pic_env_3" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_3']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_3" src="{$siteInfo['pic_env_3_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_4" value="{$siteInfo['pic_env_4']}">
                            <label data-name="pic_env_4" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_4']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_4" src="{$siteInfo['pic_env_4_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_5" value="{$siteInfo['pic_env_5']}">
                            <label data-name="pic_env_5" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_5']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_5" src="{$siteInfo['pic_env_5_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_6" value="{$siteInfo['pic_env_6']}">
                            <label data-name="pic_env_6" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_6']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_6" src="{$siteInfo['pic_env_6_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_7" value="{$siteInfo['pic_env_7']}">
                            <label data-name="pic_env_7" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_7']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_7" src="{$siteInfo['pic_env_7_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_8" value="{$siteInfo['pic_env_8']}">
                            <label data-name="pic_env_8" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_8']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_8" src="{$siteInfo['pic_env_8_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                        <div class="col col-md-4">
                            <input type="hidden" name="pic_env_9" value="{$siteInfo['pic_env_9']}">
                            <label data-name="pic_env_9" for="uploader2-input" class="add-img" data-href="{$siteInfo['pic_env_9']}" style="cursor: pointer;display:block;margin: 12px 0;text-align:center;border: 1px #888 solid"><img class="thumb" alt="pic_env_9" src="{$siteInfo['pic_env_9_thumb']}" /></label>
                            <img src="./Public/Ins/img/close_d.png" class="remove-pic" alt="remove" style="position:absolute;right:5px;top:2px;width:20px;cursor:pointer">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="operate panel panel-default col-sm-3">
        <div class="panel-body" style="font-size: 12px;">
            <h4>价格</h4>
            <volist name="majorList" id="major" key="key">
                <p><span style="width:7em;text-align:right;display:inline-block">{$major}(￥)：</span><b style="width:7em;text-align:right;display:inline-block" data-major="{$major}">0.00</b></p>
            </volist>
            <p><span style="width:7em;text-align:right;display:inline-block">实际造价：</span><b style="width:7em;text-align:right;display:inline-block" id="sum-price">0.00</b></p>

            <p><span style="width:7em;text-align:right;display:inline-block">标准造价：</span><b style="width:9em;text-align:right;display:inline-block"><input id="base-price" data-siteid="{$siteId}" type="number" class="form-control" style="text-align:right;font-size:12px;padding:0" value="{$basePrice}" {$allowEdit ? '' : 'disabled'}></b></p>
            <p><span style="width:7em;text-align:right;display:inline-block">是否超标：</span><b id="is-out" style="width:7em;text-align:right;display:inline-block">否</b></p>
            <p><b style="width:16em;text-align:right;display:inline-block"><textarea id="reason" type="text" class="form-control" placeholder="" style="display: inline-block;font-size:12px" {$allowEdit ? '' : 'disabled'}>{$reason ? $reason : '超标原因：'}</textarea></b></p>
            <p><b style="width:16em;text-align:right;display:inline-block"><textarea id="summary" type="text" data-siteid="{$siteId}" class="form-control" placeholder="" style="display: inline-block;font-size:12px" {$allowEdit ? '' : 'disabled'}>{$summary ? $summary : '盈亏总结：'}</textarea></b></p>
            <p><span style="width:7em;text-align:right;display:inline-block">年支出成本：</span><b style="width:9em;text-align:right;display:inline-block"><input id="age_limit" data-siteid="{$siteId}" type="number" class="form-control" style="text-align:right;font-size:12px;padding:0" value="{$siteInfo['age_limit']}" {$allowEdit ? '' : 'disabled'}></b> <b>元</b></p>
            <p><span style="width:7em;text-align:right;display:inline-block">年预期收入：</span><b style="width:9em;text-align:right;display:inline-block"><input id="exp_income" data-siteid="{$siteId}" type="number" class="form-control" style="text-align:right;font-size:12px;padding:0" value="{$siteInfo['exp_income']}" {$allowEdit ? '' : 'disabled'}></b> <b>元</b></p>
            <p><span style="width:7em;text-align:right;display:inline-block">静态回收期：</span><b style="width:9em;text-align:right;display:inline-block"><input id="age_limit_static" data-siteid="{$siteId}" type="number" class="form-control" style="text-align:right;font-size:12px;padding:0" value="{$siteInfo['age_limit_static']}" {$allowEdit ? '' : 'disabled'}></b> <b>年</b></p>
            <p><span style="width:7em;text-align:right;display:inline-block">星级分数：</span><b style="width:9em;text-align:right;display:inline-block"><input id="scores" data-siteid="{$siteId}" type="number" class="form-control" style="text-align:right;font-size:12px;padding:0" placeholder="0~5" value="{$siteInfo['scores']}" {$allowEdit ? '' : 'disabled'}></b> <b>分</b></p>
        </div>
    </div>
    <div class="operate panel panel-default col-sm-3">
        <div class="panel-body" style="font-size: 12px;">
            <h4>审核记录</h4>
            {:nl2br($log)}
        </div>
    </div>
</div>

<div class="modal fade add-joker" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog">
    <div class="modal-content">
        <form id="add-joker" action="{:U('add')}" method="post">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">新增</h4>
          </div>
          <div class="modal-body">
            <input type="hidden" name="site_id" value="{$siteId}">
            <input type="hidden" name="status" value="EDIT">
            <div class="row">
                <div class="form-group col-xs-12">
                    <label class="col-xs-2 control-label" for="major">专业*：</label>
                    <div class="col-xs-10">
                        <select name="major" id="major" class="form-control">
                            {:fill_option_ex($majorList)}
                        </select>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <label class="col-xs-2 control-label" for="module_id">模块*：</label>
                    <div class="col-xs-3">
                        <input type="text" class="form-control" name="module_filter" id="module_filter" value="" placeholder="关键词筛选">
                    </div>
                    <div class="col-xs-7">
                        <input type="hidden" name="module_name" id="module_name" value="">
                        <select name="module_id" id="module_id" class="form-control" required></select>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <label class="col-xs-2 control-label" for="module_price">价格￥*：</label>
                    <div class="col-xs-10">
                        <input class="form-control" type="number" id="module_price" name="module_price" min="0" step="0.01" required readonly>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <label class="col-xs-2 control-label" for="count">数量*：</label>
                    <div class="col-xs-10">
                        <input class="form-control" type="number" id="count" name="count" required min="0" step="0.00000001">
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <label class="col-xs-2 control-label" for="count">总价*：</label>
                    <div class="col-xs-10">
                        <input class="form-control" type="number" id="total_price" name="total_price" required min="0" step="0.01" value="0" readonly>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <label class="col-xs-2 control-label" for="remark">图片：</label>
                    <div class="col-xs-10">
                        <div class="input-group ">
                            <input class="form-control" name="pic"  id="pic" type="text" readonly="readonly" />
                            <div class="input-group-btn">
                                <label class="btn btn-sm btn-primary" for="uploader-input"><i class="fa fa-upload" ></i></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <label class="col-xs-2 control-label" for="remark">备注：</label>
                    <div class="col-xs-10">
                        <textarea class="form-control" type="text" id="remark" name="remark"></textarea>
                    </div>
                </div>
            </div>
          </div>
          <div class="modal-footer">
            <a id="close-add" type="button" class="btn btn-default" data-dismiss="modal">取消</a>
            <button class="btn btn-primary">保存</button>
          </div>
        </div>
    </form>
  </div>
</div>
</block>

<block name="js">
<script type="text/javascript">

moduleList = {:json_encode($moduleList)};

function loadData() {
    Ycom.ajax('{:U("groupList")}', 'get', {site_id: {$siteId}}, function (r) {
        sumPrice = {'实际造价': .0};
        if (r.code == 'ok') {
            $('table.table').html('');

            for (x in r.data) {
                sumPrice[x] = .0;
                for (y in r.data[x]) {
                    r.data[x][y]['_x'] = '<input class="ace" type="checkbox" name="id[]" value="'+ r.data[x][y].id +'" />'
                    r.data[x][y]['_pic_thumb'] = '<a href="'+ r.data[x][y].pic +'" target="__blank"><img style="max-width:100px;max-height:100px" alt="thumb" src="'+ r.data[x][y].pic_thumb +'" /></a>'

                    sumPrice['实际造价'] += Number(r.data[x][y].total_price);
                    sumPrice[x] += Number(r.data[x][y].total_price);
                }

                Ycom.table($('table.table[data-major='+x+']'), {
                    '_x': '选',
                    'module_name': '模块名',
                    'module_price': '模块价格￥',
                    'count': '模块数量',
                    'total_price': '总价',
                    '_pic_thumb': '照片',
                    'remark': '备注',
                }, r.data[x]);

                $('b[data-major='+x+']').text(sumPrice[x].toFixed(2));
            }
        } else {
            ui_error(r.msg);
        }

        $('#sum-price').text(sumPrice['实际造价'].toFixed(2));
        $('#is-out').html((sumPrice['实际造价'] > $('#base-price').val() ? '<span style="color:red">是</span>' : '否'));
    });
}

function del() {
    if($("input[name='id[]']:checked").length==0){
        ui_error('请选择要删除的内容 ');
        return;
    }
    var vars = $("#form-joker").serialize();
    ui_confirm('确定要删除吗?', function() {
        sendAjax("{:U('del')}", vars, function(data) {
            if (data.code == 'ok') {
                ui_alert(data.msg, function() {
                    loadData();
                });
            }
        });
    });
}

function apply() {
    ui_confirm('确定要发起审核吗？在审核期间不可修改模块。', function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("apply")}',
            type: 'POST',
            dataType: 'json',
            data: {site_id: '{$siteId}', reason: $('#reason').val()},
        })
        .done(function(data) {
            if (data.code == 'ok') {
                ui_alert(data.msg, function() {
                    location.reload(true);
                });
            } else {
                ui_error(data.msg);
            }
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });
}

$(document).ready(function() {
    $('img.remove-pic').click(function(event) {
        var that = this;
        var name = $(this).prev().data('name');
        ui_confirm('确定要删除此照片？', function () {
            $('input[name='+ name +']').val('');
            $('label.add-img[data-name='+ name +']').data('href', '');
            $('label.add-img[data-name='+ name +']').attr('data-href', '');
            $('img.thumb[alt='+ name +']').attr('src', './Public/Ins/img/add.png');
            Ycom.ajaxForm('#form-pic', function (result) {
                ui_info(result.info);
            });
        });
    });

    $('#button-add-joker').click(function () {
        $('#count').val('');
        $('#pic').val('');
        $('#total_price').val('0');
    });

    $('#major').change(function(event) {
        $('#module_filter').val('');

        var major = $(this).val();

        if (major == '其他') {
            $('#module_id').html('<option value="其他" data-price="0">其他</option>');
        } else {
            var html = '';
            for (x in moduleList[major]) {
                html += '<option value="'+ moduleList[major][x].id +'" data-price="' + moduleList[major][x].price + '">'+ moduleList[major][x].name +'</option>';
            }
            $('#module_id').html(html);
        }

        setTimeout(function() {
            $('#module_id').change();
            setTimeout(function() {
                $('#count').change();
            }, 100);
        }, 100);
    });

     $('#module_id').change(function(event) {
        var price = $(this).find("option:selected").data('price');
        $('#module_name').val($(this).find("option:selected").text());
        $('#module_price').val(price);

        if (price == 0) {
            $('#module_price').removeAttr('readonly');
        } else {
            $('#module_price').attr('readonly', 'readonly');
        }

        setTimeout(function() {
            $('#count').change();
        }, 100);
     });

     $('#module_price').change(function(event) {
         setTimeout(function() {
            $('#count').change();
         }, 100);
     });

     $('#add-joker').on('change input', '#count', function(event) {
        var price = $('#module_price').val();
        console.log($(this).val());
        $('#total_price').val(price * $(this).val());
     });

    $('#base-price').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), base_price: $(this).val()},
        })
        .done(function(r) {
            $('#is-out').html((sumPrice['实际造价'] > $('#base-price').val() ? '<span style="color:red">是</span>' : '否'));
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#age_limit').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), age_limit: $(this).val()},
        })
        .done(function(r) {
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#summary').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), summary: $(this).val()},
        })
        .done(function(r) {
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#exp_income').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), exp_income: $(this).val()},
        })
        .done(function(r) {
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#age_limit_static').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), age_limit_static: $(this).val()},
        })
        .done(function(r) {
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#scores').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), scores: $(this).val()},
        })
        .done(function(r) {
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#need_maintain_check').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), need_maintain_check: $(this).prop('checked') ? '1' : '0'},
        })
        .done(function(r) {
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#need_leader_check').change(function() {
        Ycom.loading.show();
        $.ajax({
            url: '{:U("site/saveA")}',
            type: 'POST',
            dataType: 'json',
            data: {id: $(this).data('siteid'), need_leader_check: $(this).prop('checked') ? '1' : '0'},
        })
        .done(function(r) {
            ui_info(r.info)
        })
        .fail(function() {
            alert('网络错误');
        })
        .always(function() {
            Ycom.loading.hide();
        });
    });

    $('#add-joker').submit(function(event) {
        Ycom.ajaxForm($(this), function(r){
            ui_info(r.msg);
            $('#close-add').click();
            loadData();
        });

        return false;
    });

    setTimeout(function() {
        $('#major').change();
    }, 100);

    loadData();

    var uploader = Ycom.Uploader();
    uploader.init(function() {
        uploader.objs.input.change(function() {
            Ycom.loading.show();
            uploader.send();
        });
    }, function(r) {
        Ycom.loading.hide();
        var result = $.parseJSON(r);
        if (result.code == 'ok') {
            $('#pic').val(result.src);
        } else {
            alert(result.msg);
        }
    }, {
        form: 'uploader-form',
        frame: 'uploader-frame',
        input: 'uploader-input',
        formAction: '{:U("upload")}',
        fileType: 'image/jpeg, image/jpg, image/png, image/gif',
        // fileType: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    });

    imgName = '';

    $('.add-img').click(function () {
        imgName = $(this).data('name');

        if ($(this).data('href')) {
            window.open($(this).data('href'));
            return false;
        }
    });

    $('#module_filter').on('change',function(event) {
        $('#module_id').change();
    });

    $('#module_filter').on('change input paste',function(event) {
        var key = $.trim($(this).val());
        var major = $('#major').val();


        var html = '';
        for (x in moduleList[major]) {
            if (key) {
                if (moduleList[major][x].name.indexOf(key) > -1) {
                    html += '<option value="'+ moduleList[major][x].id +'" data-price="' + moduleList[major][x].price + '">'+ moduleList[major][x].name +'</option>';
                }
            } else {
                html += '<option value="'+ moduleList[major][x].id +'" data-price="' + moduleList[major][x].price + '">'+ moduleList[major][x].name +'</option>';
            }
        }

        $('#module_id').html(html);
    });

    var uploader2 = Ycom.Uploader();
    uploader2.init(function() {
        uploader2.objs.input.change(function() {
            Ycom.loading.show();
            uploader2.send();
        });
    }, function(r) {
        Ycom.loading.hide();
        var result = $.parseJSON(r);
        if (result.code == 'ok') {
            $('input[name='+ imgName +']').val(result.src);
            $('img.thumb[alt='+ imgName +']').attr('src', result.src);
            $('label.add-img[data-name='+ imgName +']').data('href', result.src);
            $('label.add-img[data-name='+ imgName +']').attr('data-href', result.src);

            Ycom.ajaxForm('#form-pic', function (result) {
                ui_info(result.info);
            });
        } else {
            alert(result.msg);
        }
    }, {
        form: 'uploader2-form',
        frame: 'uploader2-frame',
        input: 'uploader2-input',
        formAction: '{:U("upload", ['hq' => true])}',
        fileType: 'image/jpeg, image/jpg, image/png, image/gif',
        // fileType: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    });
});
</script>
</block>
